const typeService = require('../service/type.service')


class MomentController {
    async list(ctx, next) {

        const result = await typeService.getTypeList();

        ctx.body = result;
    }
    async detail(ctx, next) {
        const { typeId } = ctx.params;
        console.log(typeId);

        const result = await typeService.getTypeById(typeId);

        ctx.body = result;
    }
    async create(ctx, next) {
        const type = ctx.request.body;
        const result = await typeService.create(type);
        console.log(result);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }

    }
    async edit(ctx, next) {
        const type = ctx.request.body;
        const result = await typeService.edit(type);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }
    }
    async remove(ctx, next) {
        // 1.typeId
        const { typeId } = ctx.params;

        // 2.删除内容
        const result = await typeService.remove(typeId);
        if (result.length >= 1) {
            ctx.body = {
                code: 0,
                message: ''
            };
        } else {
            ctx.body = {
                code: 400,
                message: '请求错误'
            };
        }
    }
}

module.exports = new MomentController();